package com.cr.service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.cr.dao.MyOrderDao;
import com.cr.model.MyOrder;

public class MyOrderService {
	private MyOrderDao dao=new MyOrderDao();
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	public MyOrder getMyOrder(long id)
	{
		return dao.getMyOrder(id);
	}
	/**
	 * 
	 * @param code
	 * @return
	 */
	public MyOrder getMyOrder(String code)
	{
		if(code==null)
			return null;
		return dao.getMyOrder(code);
	}
	/**
	 * 
	 * @param myOrder
	 * @return
	 */
	public boolean addMyOrder(MyOrder myOrder)
	{
		if(myOrder==null)
			return false;
		Date now=new Date();
		SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String orderDate=sdf2.format(now);
		myOrder.setOrderDate(orderDate);
		
		return dao.addMyOrder(myOrder);
	}
	/**
	 * 
	 * @param myOrder
	 * @return
	 */
	public boolean updateMyOrder(MyOrder myOrder)
	{
		if(myOrder==null)
			return false;
		return dao.updateMyOrder(myOrder);
	}
	/**
	 * 
	 * @param id
	 * @return
	 */
	public boolean deleteMyOrder(long id)
	{
		return dao.deleteMyOrder(id);
	}
	
	/**
	 * 
	 * @param start
	 * @param limit
	 * @param condition
	 * @return
	 */
	public List<MyOrder> getOrders(int currPage,int pageSize,String condition)
	{
		int start=(currPage-1)*pageSize;
		int limit=pageSize;
		return dao.getOrders(start, limit, condition);
	}
	
	/**
	 * 
	 * @param condition
	 * @return
	 */
	public int getCount(String condition)
	{
		return dao.getCount(condition);
	}

}
